//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.custom.gallery;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory.Options;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader.TileMode;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.Gallery.LayoutParams;

public class ReflectionImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;
    private int[] mImageIds;
    private ImageView[] mImages;
    private int temph = 128;
    private int tempw = 128;

    public ReflectionImageAdapter(Context c, int[] ImageIds, int weight, int hight) {
        this.mContext = c;
        this.mImageIds = ImageIds;
        this.mImages = new ImageView[this.mImageIds.length];
        this.temph = hight;
        this.tempw = weight;
        this.createReflectedImages();
    }

    private void createReflectedImages() {
        int index = 0;
        int[] var6 = this.mImageIds;
        int var5 = this.mImageIds.length;

        for(int var4 = 0; var4 < var5; ++var4) {
            int imageId = var6[var4];
            Options opts = new Options();
            opts.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(this.mContext.getResources(), imageId, opts);
            opts.inSampleSize = computeSampleSize(opts, -1, this.tempw * this.temph);
            opts.inJustDecodeBounds = false;

            try {
                Bitmap originalImage = BitmapFactory.decodeResource(this.mContext.getResources(), imageId, opts);
                int width = originalImage.getWidth();
                int height = originalImage.getHeight();
                Matrix matrix = new Matrix();
                matrix.preScale(1.0F, -1.0F);
                Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false);
                Bitmap bitmapWithReflection = Bitmap.createBitmap(width, height + height / 2, Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmapWithReflection);
                canvas.drawBitmap(originalImage, 0.0F, 0.0F, (Paint)null);
                Paint defaultPaint = new Paint();
                canvas.drawRect(0.0F, (float)height, (float)width, (float)(height + 4), defaultPaint);
                canvas.drawBitmap(reflectionImage, 0.0F, (float)(height + 4), (Paint)null);
                Paint paint = new Paint();
                LinearGradient shader = new LinearGradient(0.0F, (float)originalImage.getHeight(), 0.0F, (float)(bitmapWithReflection.getHeight() + 4), 1895825407, 16777215, TileMode.CLAMP);
                paint.setShader(shader);
                paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
                canvas.drawRect(0.0F, (float)height, (float)width, (float)(bitmapWithReflection.getHeight() + 4), paint);
                ImageView imageView = new ImageView(this.mContext);
                imageView.setImageBitmap(bitmapWithReflection);
                imageView.setLayoutParams(new LayoutParams(this.tempw, this.temph));
                this.mImages[index++] = imageView;
            } catch (OutOfMemoryError var19) {
                ;
            }
        }

    }

    public int getCount() {
        return this.mImageIds.length;
    }

    public Object getItem(int position) {
        return Integer.valueOf(position);
    }

    public long getItemId(int position) {
        return (long)position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        return this.mImages[position];
    }

    public float getScale(boolean focused, int offset) {
        return Math.max(0.0F, 1.0F / (float)Math.pow(2.0D, (double)Math.abs(offset)));
    }

    private static int computeSampleSize(Options options, int minSideLength, int maxNumOfPixels) {
        int initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels);
        int roundedSize;
        if(initialSize <= 8) {
            for(roundedSize = 1; roundedSize < initialSize; roundedSize <<= 1) {
                ;
            }
        } else {
            roundedSize = (initialSize + 7) / 8 * 8;
        }

        return roundedSize;
    }

    private static int computeInitialSampleSize(Options options, int minSideLength, int maxNumOfPixels) {
        double w = (double)options.outWidth;
        double h = (double)options.outHeight;
        int lowerBound = maxNumOfPixels == -1?1:(int)Math.ceil(Math.sqrt(w * h / (double)maxNumOfPixels));
        int upperBound = minSideLength == -1?128:(int)Math.min(Math.floor(w / (double)minSideLength), Math.floor(h / (double)minSideLength));
        return upperBound < lowerBound?lowerBound:(maxNumOfPixels == -1 && minSideLength == -1?1:(minSideLength == -1?lowerBound:upperBound));
    }
}
